package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import bo.Cita;

public class JDBCCitaDAO implements ICitaDAO {

	@Override
	public void delete(Connection conn, String citaOID) {
		String sql = "DELETE FROM Cita WHERE (OID = ?) ";
		PreparedStatement stmt = null;

		try {
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, citaOID);
			stmt.executeUpdate();
		} catch (SQLException e) {
			System.err.println("Message: " + e.getMessage());
			System.err.println("SQLState: " + e.getSQLState());
			System.err.println("ErrorCode: " + e.getErrorCode());
		} finally {
			try {
				if (stmt != null)
					stmt.close();
			} catch (SQLException e) {
			}
		}

	}

	@Override
	public void insert(Connection conn, String citaOID, Cita c) {
		String sql = "INSERT INTO Cita ( OID, horaInicio, duracion, OIDUsuario) VALUES (?, ?, ?) ";
		PreparedStatement stmt = null;
		
		try {
            stmt = conn.prepareStatement(sql);

            stmt.setString(1, citaOID);
            stmt.setInt(1, c.getHoraInicio().getHora());
            stmt.setInt(3, c.getHoraInicio().getMinuto());
            stmt.setInt(3, c.getDuracion().getHora());
            stmt.setInt(3, c.getDuracion().getMinuto());
  ///DUDAS!!          stmt.setString(4, c.getUsuario().get);

            stmt.executeUpdate();

        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
            }
        }
	}

	@Override
	public Cita select(Connection conn, String citaOID) {
		// TODO Auto-generated method stub
		return null;
	}

}
